package org.example.springboot.service.impl;


import org.example.springboot.dao.BrandDAO;
import org.example.springboot.dao.impl.BrandDAOImpl;
import org.example.springboot.entity.Brand;
import org.example.springboot.entity.PageEntity;
import org.example.springboot.service.BrandService;

import java.util.List;

public class BrandServiceImpl implements BrandService {

    //调用dao层对象
    private BrandDAO brandDAO = new BrandDAOImpl();

    @Override
    public PageEntity<Brand> findBrandPage(Integer current, Integer pageSize) {
        //查询品牌总数（*）
        int total = brandDAO.selectBrandCount();
        //分页查询品牌数据 limit
        List<Brand> brands = brandDAO.selectBrandlimit((current-1)*pageSize,pageSize);
        //包装数据发送给前端
        PageEntity<Brand> pageEntity = new PageEntity<>();
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setCurrent(current);
        pageEntity.setRecords(brands);
        return pageEntity;
    }

    @Override
    public List<Brand> findAll() {
        return brandDAO.selectAll();
    }

    @Override
    public Brand findById(String brandId) {
        return brandDAO.selectById(brandId);
    }

    @Override
    public boolean save(Brand brand) {
        return brandDAO.insert(brand);
    }

    @Override
    public boolean remove(String brandId) {
        return brandDAO.delete(brandId);
    }

    @Override
    public boolean update(Brand brand) {
        return brandDAO.update(brand);
    }
}
